interface Iutils {
    toCelsius:(tem:number)=>number
    toFahrenheit:(tem:number)=>number
    [k:string]:any
}

let utils:Iutils = {
    toCelsius(tem){
        return ((tem -32)*5)/9 
    },
    toFahrenheit(tem){
        return (tem*9)/5+32
    }
}

/**
 * 过滤和转换温度
 * @param temperature 输入的温度
 * @param convert 转换函数的名
 * @returns 返回计算的结果
 */

type ItryConvert = (convert:string,temperature:string) => string

type IisNaN=(params:any)=>boolean
let isNaN2:IisNaN =window.isNaN

let tryConvert:ItryConvert=(convert,temperature)=>{
    if(isNaN2(temperature) || temperature ===''){
        return ''
    }
    const input = parseFloat(temperature)

    const output = utils[convert](input)
    const rounded = Math.round(output * 1000) / 1000
    return rounded.toString()
}
export default tryConvert